class Slot:
    def __init__(self,role,content,name=None,options=None):
        self.role = role  #语义角色，如user，system，tool等
        self.content = content  #slot文本内容
        self.name = name # 可选名称
        self.options = options or {}

    def __repr__(self):
        name = self.name if self.name else ""
        tag = f"{self.role.upper()}- {name}"
        return f"[{tag} \n {self.content}"

    def to_dict(self):
        slot = {"role":self.role,"content":self.content}
        if self.name:
            slot["name"] = self.name
        return slot



if __name__ == "__main__":
    #构建多个语义角色的slot
    slots = [
        Slot("user","请检查以下代码是否存在性能",name="CodeReview"),
        Slot("system","你是性能优化专家",name="CodeReview"),
    ]
    for slot in slots:
        print(slot.to_dict())